package number

// https://leetcode-cn.com/contest/weekly-contest-202/problems/minimum-operations-to-make-array-equal/
// 穷举，等差数列求和
func MinOperations(n int) int {
	if n == 1 {
		return 0
	} else if n == 2 {
		return 1
	} else if n == 3 {
		return 2
	}
	n = n - 1
	if n%2 == 1 {
		if (n+1)%4 == 0 {
			return (1 + n) * ((n + 1) / 4)
		} else {
			return (1+n)*((n+1)/4) + (n+1)/2
		}
	} else {
		if n/2%2 == 0 {
			return (2 + n) * (n / 4)
		} else {
			return (2+n)*(n/4) + (n+2)/2
		}
	}
}
